<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
 <!DOCTYPE html>
<html>

<head>
	<base href="/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>下级用户列表</title>
    <meta name="keywords" content="下级用户列表">
    <meta name="description" content="下级用户列表">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="static/templet/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="static/templet/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="static/templet/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="static/templet/css/animate.min.css" rel="stylesheet">
    <link href="static/templet/css/style.min862f.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
    <form action="user/child/list" method="post" id="userForm">
        <div class="row">
        	<div class="col-sm-12">
        		<table class="table table-hover">
        			<tr>
        				<td>
							 <input value="${param.userName}" name="userName" class="form-control" placeholder="请输入用户名">
        				</td>
        				<td>
							 <input value="${param.phone}" name="phone" class="form-control" placeholder="请输入手机号">
        				</td>
        				<td>
        					<select class="form-control" name="state" id="state" data-placeholder="搜索引擎">
					            <option value="">状态</option>
					            <option value="01" <c:if test="${param.state == '01'}">selected</c:if>>启用</option>
					            <option value="02" <c:if test="${param.state == '02'}">selected</c:if>>禁用</option>
					        </select>
        				</td>
						<td>
        					<select class="form-control" name="serviceState" id="serviceState" data-placeholder="搜索引擎">
					            <option value="">服务状态</option>
					            <option value="00" <c:if test="${param.serviceState == '00'}">selected</c:if>>服务中</option>
					            <option value="01" <c:if test="${param.serviceState == '01'}">selected</c:if>>已停用</option>
					        </select>
        				</td>
        				<td>
        					<select class="form-control" name="isDelete" id="isDelete" data-placeholder="是否删除">
					            <option value="00" <c:if test="${param.isDelete == '00'}">selected</c:if>>未删除</option>
					            <option value="01" <c:if test="${param.isDelete == '01'}">selected</c:if>>已删除</option>
					        </select>
        				</td>
        				<td>
        					<button type="button" class="btn btn-primary" onclick="searchs();">检索</button>
        				</td>
        			</tr>
        		</table>
			</div> 
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                    	<a class="btn btn-primary " href="javascript:add();" target="_self">新增</a>
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>用户名</th>
                                    <th>联系人</th>
                                    <th>角色</th>
                                    <th>联系电话</th>
                                    <th>邮箱</th>
                                    <th>查看关键词</th>
                                    <th>昨日达标数</th>
                                    <th>昨日消费金额</th>
                                    <th>预计消费天数</th>
                                    <th>余额</th>
                                    <th>最低余额</th>
                                    <th>信誉值</th>
                                    <th>状态</th>
                                    <th>服务状态</th>
                                    <th>是否删除</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
							<c:forEach items="${page.list}" var="user" varStatus="vs">
                            	<tr>
                                    <td>${user.userName }</td>
									<td>${user.petName }</td>
									<td>${user.roleName }</td>
									<td>${user.phone }</td>
									<td>${user.email }</td>
									<td>
									<a href="javascript:keyWordList('${user.id }')">查看</a>
									</td>
									<td>${user.yCnt }</td>
									<td>${user.yConsume }</td>
									<td>
										<c:choose>
											<c:when test="${user.yConsume.unscaledValue() eq 0}">
												<c:choose>
													<c:when test="${user.balance le 0}">
														0
													</c:when>
													<c:otherwise>-</c:otherwise>
												</c:choose>
											</c:when>
											<c:otherwise>
												<c:choose>
													<c:when test="${user.balance le 0}">
														0
													</c:when>
													<c:otherwise>
														<fmt:formatNumber type="number" value="${(user.balance-user.balance%user.yConsume)/user.yConsume}"/>
													</c:otherwise>
												</c:choose>
											</c:otherwise>
										</c:choose>
									</td>
									<td>${user.balance }</td>
									<td>${user.minQuota < 0 ? '未设置':user.minQuota}</td>
									<td>${user.creditValue }</td>
									<td>
									<c:choose>
                                    	<c:when test="${user.state eq '01' }">
                                    	启用
                                    	</c:when>
                                    	<c:otherwise>
                                    	禁用
                                    	</c:otherwise>
                                    </c:choose>
									</td>
									<td>
									<c:choose>
                                    	<c:when test="${user.serviceState eq '01' }">
                                    	已停用
                                    	</c:when>
                                    	<c:otherwise>
                                    	服务中
                                    	</c:otherwise>
                                    </c:choose>
									</td>
									<td>
									<c:choose>
                                    	<c:when test="${user.isDelete eq '01' }">
                                    	已删除
                                    	</c:when>
                                    	<c:otherwise>
                                    	正常
                                    	</c:otherwise>
                                    </c:choose>
									</td>
                                    <td>
                                    <c:choose>
                                    <c:when test="${user.isDelete eq '00' }">
                                    	
	                                    <a class="fa fa-tags" href="javascript:resetPwd('${user.id}');" title="重置密码"></a>
	                                    
	                                    <c:choose>
	                                    	<c:when test="${user.roleCode eq 'proxy' }">
	                                    		 <a class="fa fa-money" href="javascript:proxyPrices('${user.id}','${user.roleId}');" title="代理价"></a>
	                                    	</c:when>
	                                    	<c:otherwise>
	                                    		 <a class="fa fa-money" href="javascript:proxyPrice('${user.id}');" title="价格"></a>
	                                    	</c:otherwise>
                                    	</c:choose>
	                                    <a class="fa fa-edit" href="javascript:edit('${user.id}');" title="编辑"></a> 
	                                    <a class="fa fa-trash-o" href="javascript:deleteUser('${user.id}');" title="删除"></a>
	                                    
	                                    <c:choose>
	                                    	<c:when test="${user.state eq '01' }">
	                                    	<a class="fa fa-close" href="javascript:updateState('${user.id}','00');" title="禁用"></a>
	                                    	</c:when>
	                                    	<c:otherwise>
	                                    	<a class="fa fa-check" href="javascript:updateState('${user.id}','01');" title="启用"></a>
	                                    	</c:otherwise>
	                                    </c:choose>
	                                    <!-- <a href="javascript:domainView('${sessionUser.userName}.${seoDomain }');" title="访问地址">访问地址</a> -->
                                    </c:when>
                                    <c:otherwise>
                                    	不可操作
                                    </c:otherwise>
                                    </c:choose>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                        
                        <jsp:include page="/WEB-INF/jsp/page.jsp">
                        	<jsp:param value="userForm" name="form"/>
                        </jsp:include>
                    </div>
                </div>
            </div>
        </div>
        </form>
    </div>
    <script src="static/templet/js/jquery.min.js?v=2.1.4"></script>
    <script src="static/templet/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="static/templet/js/plugins/peity/jquery.peity.min.js"></script>
    <script src="static/templet/js/plugins/layer/layer.min.js"></script>
    <script src="static/templet/js/iframe.min.js"></script>
    <script type="text/javascript">
    
    function searchs(){
    	$("#userForm").submit();
    }
    
    function add(){
    	parent.layer.open({
    	    type: 2,
    	    title: '用户',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['40%', '80%'],
    	    content: 'user/add',
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }

    function domainView(domain){
    	parent.layer.alert(domain);
    }
    
    function edit(userId){
    	parent.layer.open({
    	    type: 2,
    	    title: '用户',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['40%', '80%'],
    	    content: 'user/edit?userId='+userId,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }
    
    function resetPwd(userId){
    	parent.layer.open({
    	    type: 2,
    	    title: '重置密码',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['40%', '80%'],
    	    content: 'user/toResetPwd?userId='+userId,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }
    
    function keyWordList(userId){
    	parent.layer.open({
    	    type: 2,
    	    title: '关键词',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['95%', '90%'],
    	    content: 'keyWordGE/list?userId='+userId,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }
    
    function proxyPrice(userId){
    	parent.layer.open({
    	    type: 2,
    	    title: '设置代理价',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['40%', '80%'],
    	    content: 'user/price?userId='+userId,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }
    
    function proxyPrices(userId, roleId){
    	parent.layer.open({
    	    type: 2,
    	    title: '设置代理价',
    	    shadeClose: true,
    	    shade: 0.8,
    	    area: ['40%', '80%'],
    	    content: 'user/proxyPrices?userId='+userId+'&roleId='+roleId,
    	    cancel:function(index, layero){
    	    	iframe.get(layero);
    	    	if(result == 1){
    	    		location.reload(true);
    	    	}
    	    	
    	    }
    	});
    }
    
    function deleteUser(userId){
    	parent.layer.confirm('确定删除吗？', {
    	    btn: ['确定'], //按钮
    	    shade: false //不显示遮罩
    	}, function(){
    		$.get("user/deleteUser?id="+userId,function(data,status){
    			console.log(data)
        		if(status == 'success'){
        			var result = data.result;
        			if(result.state == '1'){
        				parent.layer.msg('删除成功', {icon: 1});
        				location.reload();
        			}else{
 
        				parent.layer.msg(result.message, {icon: 1});
        			}
        		}
        	},"json")
    	});
    	
    }
    
    function updateState(userId, state){
    	parent.layer.confirm('确定更改吗？', {
    	    btn: ['确定'], //按钮
    	    shade: false //不显示遮罩
    	}, function(){
    		$.post("user/updateState",{id:userId, state:state},function(data,status){
        		
        		if(status == 'success'){
        			var result = data.result;
        			if(result.state == '1'){
        				parent.layer.msg('修改成功', {icon: 1});
        				location.reload();
        			}else{
 
        				parent.layer.msg(result.message, {icon: 1});
        			}
        		}
        	})
    	});
    	
    }
    </script>

</body>

</html>